# -*- coding: utf-8 -*-
import requests
from lxml import etree
import re
import sys
import os
os.chdir('/root/yy/MeiHaoTong')
sys.path.append('/root/yy/MeiHaoTong')
from MeiHaoTong.settings import MYSQL_SETTINGS,ACCOUNT,COOKIE_TABLE
from MeiHaoTong.login_failure import FailMail
import time
import pymysql

lis_cate = [{'327': [('gh_363b924965e9', '人民日报'), ('gh_05d833e54446', '占豪'), ('gh_6651e07e4b2d', '新华社'), ('wxid_pzhf43hmwizd11', '央视新闻'), ('gh_ba6105d7c051', '冯站长之家'), ('gh_faa35168f414', '新闻哥'), ('gh_572b3506a44f', '侠客岛'), ('gh_95b0feda9646', '环球时报'), ('gh_2837b93c1976', '参考消息'), ('gh_d62474859d61', '人民网'), ('gh_771635949f86', '军武次位面'), ('gh_41575c96fbf5', '今日头条'), ('gh_68b976f584b5', '新华网'), ('gh_8956ac11363e', '中央政法委长安剑'), ('gh_0008713c31f5', '瞭望智库'), ('gh_11d6ef0dd9d4', '新闻早餐'), ('gh_14ef0e644b8f', '铁血军事'), ('gh_a7bbb71d655c', '中国新闻周刊'), ('gh_5c9e0938601d', '观察者网'), ('gh_e3ae8ac3dd21', '半月谈')]},{'328': [('gh_2ba2404c01c0', '差评'), ('wxid_5637156371511', '果壳'), ('gh_70949f33590e', '小道消息'), ('wxid_7620846208112', '虎嗅APP'), ('gh_b0c8e40b170f', '科技美学'), ('gh_656e67a6d645', '互联网研究家'), ('gh_80d2528f3dcd', 'AppSo'), ('gh_d0e8fa0609a2', '科技每日推送'), ('gh_e59ba9dfaa66', '知乎日报'), ('gh_0ac3112b7a75', '网红前线'), ('gh_1fa52b903043', '哎咆科技'), ('gh_ebaabaf37033', '互联网观察'), ('gh_2db1e95c29bb', 'ZEALER'), ('gh_8e217150b0ec', 'stormzhang'), ('gh_c1ed3122ddb1', '兔玩在线'), ('gh_e970fb56ec3c', '王者小信'), ('gh_82a2e55f24ab', '互联网思维'), ('gh_27c43c799b0c', 'DeepTech深科技'), ('gh_116265e896ed', '互联网圈内事'), ('gh_6e5cdb3a829a', 'NASA爱好者')]},{'329': [('gh_63fc3c853726', '车叫兽'), ('gh_be467c3d2b93', '汽车之家'), ('gh_5972b78fdac0', '李老鼠说车'), ('gh_3b8b4fb8a34b', '一起去SUV'), ('gh_16ef9d7b6fe8', '大家车言论'), ('gh_5ffd956d7330', '懂车'), ('gh_6c40d781af1f', '30秒懂车'), ('gh_9e260264ed55', '玩车教授'), ('gh_519680149d27', '有车以后'), ('gh_78fc1408e69b', '小新说车'), ('gh_092f6c4fea0e', '微路况'), ('wxid_2732347323221', '江苏交通广播网'), ('gh_92adc4e72b56', '汽车洋葱圈'), ('gh_b3bc9642b7a1', '改装车'), ('gh_2de67f4aaeb7', '改车志'), ('gh_acd361344819', '汽修宝典'), ('gh_e24362d00154', '摩托车杂志'), ('car896', '896汽车调频'), ('gh_71f02a48a025', '豪哥说车'), ('gh_73fb57878bdf', '金鸽传媒')]},{'330': [('gh_e27183c15daf', '装修33天'), ('gh_38edf5b3d18e', '菠萝斑马居住指南'), ('gh_ef7f25df8a8e', '广州房产'), ('gh_26f157f3e2b1', '明源地产研究院'), ('gh_217ae9428424', '筑龙施工'), ('gh_b3ba3f352401', '杭州楼市动态'), ('gh_0719da708106', '花田大叔'), ('gh_badc243b4a25', '筑客HOME'), ('gh_92dc6a0addb4', '热家居'), ('gh_c77a9a39f512', '绘本家居'), ('gh_3eb142fcd154', '又有好物推荐'), ('gh_ffbf84ad8b05', '国际家居'), ('gh_f4504a0e2ded', '一房一万'), ('gh_25925ad97e99', '工程行业'), ('gh_437ad57865d3', '地产观察'), ('gh_007d8c18cd12', '设计本'), ('wxid_5838958388911', '时尚家居'), ('gh_4b70b95b1f40', '室内设计联盟'), ('gh_d65597709a0b', '环球创意家居'), ('gh_bcf6b4932f2f', '装修效果图')]},{'331': [('gh_04faa23eb9ed', 'LinkedIn'), ('gh_4c81fe8fd059', '薪人薪事企小薪'), ('gh_462cb74fd375', '小警之家'), ('gh_bca644cdc222', '庞门正道'), ('gh_de14faa82f78', '秋叶PPT'), ('gh_4dfa9862903f', '智联招聘'), ('gh_7d7f03a628ac', '刑事实务'), ('gh_b35b38c2cf55', 'HRBar'), ('gh_64bfea1cafb8', '警界'), ('gh_4bad490759a1', 'Excel精英培训'), ('gh_50c254116150', '改变自己'), ('gh_0af747913cab', '阿SIR'), ('gh_e832e065602a', 'G.P.A'), ('gh_234b648ef667', '会计说'), ('gh_2511b38ed5c8', '每天学点HR'), ('gh_980f636d96f3', '爱折腾的壹休'), ('gh_891d49f9dfcf', '一级建造师考试'), ('gh_f4f286da622c', '丁香人才'), ('gh_e7594774756c', '人力资源分享汇'), ('gh_66328d6c9573', 'DreambigCareer')]},{'332': [('gh_e1771b68833c', '林奇'), ('gh_53c502cb17fa', '新财迷'), ('gh_9dc0e48d383a', '央视财经'), ('gh_2296f0eb822f', '光明财经'), ('gh_1ebe1a3ab58a', '老斯基财经'), ('gh_85bf9d376e41', '中国经济网'), ('gh_6df2146bcb82', '券商中国'), ('gh_64b9211187ab', '华尔街见闻'), ('gh_f695ceb50c87', '股票牛股'), ('gh_95c45d00c020', '财经早餐'), ('gh_b8057057165a', 'A股铁娘子'), ('gh_e78cad3db013', '股市热点1号'), ('wxid_7982809829512', '每日经济新闻'), ('gh_bdb88ebf703f', '财经新闻'), ('wxid_4uidjxlafusk21', '21世纪经济报道'), ('gh_1c8fdcc648cc', '财经连环话'), ('gh_1dc72c1579ab', '新财富'), ('gh_35ec0049c78d', '股票早餐'), ('gh_92bd73cfb581', '华商韬略'), ('wxid_2900919009212', '21财闻汇')]},{'333': [('gh_cfb44105ebb8', 'ONE文艺生活'), ('gh_48345b7a0f3c', '局座召忠'), ('gh_844ed391e3d0', '生活茂'), ('gh_e13f0ebff922', '骏景农业'), ('gh_e94f3c95d65a', '新世相'), ('gh_5c68c9765bb4', '狗与爱的世界'), ('gh_aae41e83ea38', '地球在线'), ('gh_c44f30be49b5', '动态相册'), ('gh_ad83df020808', '感恩生活'), ('gh_469fde0b896d', '大爱狗狗控'), ('gh_e4c36c6f1cd4', 'CCTV生活圈'), ('wxid_9099770999011', '壹读'), ('gh_6baaf9445371', '广东公共DV现场'), ('gh_0567c090f838', '一条'), ('gh_0a9f33207d9b', '小资SHOW'), ('gh_e611a0e288d9', 'Voicer'), ('gh_119ace513df3', '良仓'), ('gh_9fa970e2561a', '顾爷'), ('gh_d44604ba14cf', '上海圈子'), ('gh_f27ca3831aea', '物道')]},{'334': [('gh_ab1ffb2c3464', '夜听'), ('gh_51514ba3fea6', '爱的家园'), ('gh_32bf1d8ec741', '一星期一本书'), ('gh_c3f802a0175d', '视觉志'), ('gh_24bf8068e2b5', '美闻参阅'), ('gh_b6cf70ee486a', '卡娃微卡'), ('gh_9b9c85f96827', '天天炫拍'), ('gh_0652140e5306', '蕊希'), ('gh_08a5e67cf297', '点点星光'), ('gh_5d94514a127c', '一禅小和尚'), ('gh_0de0de7c2866', '剑圣喵大师'), ('gh_99766370ece6', '诗词天地'), ('gh_d3d56d336c35', '三剑客'), ('gh_18e80e0c3c30', '二更'), ('gh_2bad56fcda7f', '一读'), ('gh_109f27a7e1f1', '佛佛佛'), ('gh_fbc3b89024ae', '小北'), ('gh_f064da8b79d5', '牛弹琴'), ('gh_53737dbd4c29', '不二大叔'), ('gh_257a3b2d1c9a', '清南师兄')]},{'335': [('gh_95d87a6a5865', '她刊'), ('gh_a13bfdafc5fd', 'Lisa的美妆日记'), ('gh_a446892f7007', 'gogoboi'), ('gh_e64edbd1b627', '风茕子'), ('gh_cae729c1e8c7', '石榴婆报告'), ('gh_a318058dabae', '深夜种草'), ('gh_2e0bd8dd368d', 'FashionWeek'), ('gh_f3a32d5b0c84', '商务范'), ('gh_e362be747e75', '服装搭配师miuo'), ('gh_9c790172eb54', '居里先生LaVie'), ('gh_3e24d2d4c369', '更美'), ('gh_189335c8b90e', '卡妞范儿'), ('gh_eff317f7a265', '睡前一起夜听'), ('gh_f55b4a632bc2', '1626潮流精选'), ('gh_e29b59883421', '1公斤小姐'), ('gh_797a6fa90bf0', '蝉创意'), ('gh_4dd474ca8ef1', 'Jessica时髦精'), ('gh_31326765d0e0', 'X分子'), ('trendscosmo', '时尚COSMO'), ('gh_4ea3df7a8995', '潮库')]},{'336': [('gh_6b637d4e8ec6', '原来是柒公子'), ('gh_70d70c8d03a4', 'FashionTrip'), ('gh_b1cb5653b390', '周末去哪玩'), ('gh_a9c02330d5aa', '中国国家地理'), ('gh_4ede88c6ffb4', '吃喝玩乐在深圳'), ('wxid_1944979462311', '穷游网'), ('gh_c9a036c9b887', '背包旅行摄影'), ('gh_262a8cca8bd4', '环球旅行'), ('gh_336ea9863c03', '带你游遍英国'), ('gh_9a4d15303ea7', '水光山色'), ('gh_4ef98011424e', '背包旅行'), ('gh_7707f4aca721', '最美风景在路上'), ('gh_3e47a7328c31', '爱奇旅'), ('gh_61f884b75d2a', '徒步中国'), ('gh_f26f1c27fd43', '一日三图'), ('gh_3ad1c94903ea', '大连玩乐会'), ('gh_4156771c305d', '无锡攻略'), ('gh_8935cfadd816', '最美食材'), ('gh_388ef28883e8', '祖国山河风光'), ('gh_1ab1f4e0252a', '郑州出发')]},{'337': [('wxid_4302923029011', '丁香医生'), ('gh_c1ffdd9d38d1', '练瑜伽'), ('gh_038cf5c345ed', '丁香生活研究所'), ('wxid_9602156020911', '丁香园'), ('gh_5abd99466e94', '全球健身指南'), ('gh_1caea018d955', '脉脉养生'), ('gh_049d4de5f555', 'BTV我是大医生官微'), ('gh_172276f84eb8', '养生固本健康人生'), ('gh_2cba95355b94', '健康养身'), ('gh_747a762965a5', '华医网'), ('gh_339f52e33eb1', '健康与长寿'), ('gh_6dbe082427af', '零点养身'), ('gh_5aeb8a109a49', '生命时报'), ('gh_44d75027a6ec', '艾灸5555'), ('gh_4e41b7e1d96e', '道医'), ('gh_96a09498e5aa', '囚徒健身'), ('gh_8c9aed08848d', '用武之地'), ('gh_d15cda1926d6', '名医话养生'), ('gh_66ff5cf4abf9', '健康时报'), ('gh_71a08c5989ab', '瑜伽路上')]},{'338': [('gh_f01a9053bbcc', '什么值得吃'), ('gh_d1ce402c28b3', '菜菜美食日记'), ('gh_b19a34aa74ef', '美食台'), ('gh_1a7773e47475', '王大厨的美食日记'), ('gh_d2301d3cd405', '北京美食攻略'), ('gh_7bd7bed70e95', '武汉吃货'), ('gh_d743fe127e24', '连咖啡微服务'), ('gh_cc82c8ce0ef6', '东莞美食大搜罗'), ('gh_c16fb451c1b3', '郑州吃货团'), ('gh_5f03a96c9121', '央七食尚大转盘'), ('gh_7a8053d98913', '美味菜谱'), ('gh_c00fe9792166', '魔都吃货小分队'), ('gh_ba3ed42996c1', '詹姆士的厨房'), ('gh_0ae98f29547c', '食帖'), ('gh_08fd862a7e90', '企鹅吃喝指南'), ('gh_1056579374ac', '艾格吃饱了'), ('wxid_7659306593111', '下厨房'), ('gh_a3cc443f063c', '长沙吃货'), ('gh_8e0afa37de60', '酒业家'), ('gh_50f966396ba7', '逛吃杭州')]},{'339': [('lengtootoo', '冷兔'), ('gh_8abfde54fc60', '蒲街坊'), ('lengxiaohua450114', '冷笑话'), ('gh_fb2929af2f84', '六点半'), ('gh_f014862b32a9', '唐唐频道'), ('gh_028c33dfd807', '粤知一二'), ('wxid_6449084490911', '冷笑话精选'), ('gh_9c3414d9dde8', '少女兔'), ('gh_e853ac38df79', '槽值'), ('gh_19d9bd4368b5', '三江锅'), ('gh_4924dfc59a65', '每日音乐'), ('gh_a7700a3fd604', '奔波儿灞与灞波儿奔'), ('gh_e3e0b19f7a8b', '木偶诡异漫画'), ('gh_7273a02c7e7e', '王者荣耀'), ('gh_f5a2ad9cef98', '今日热点聚焦'), ('gh_e7d6e7b121d0', '同道大叔'), ('gh_64689a331b8c', '天天逗事'), ('gh_d15570b17866', '东七门'), ('gh_454c72cee2a2', '一只学霸'), ('gh_c2aff21e48ec', '糗事百科')]},{'340': [('gh_7e7a93c4a824', '乌鸦电影'), ('gh_31a2f16c71cc', '豆瓣电影'), ('gh_7ee7bd705863', '毒舌美少女'), ('gh_47b4f3063cfa', '独立鱼电影'), ('gh_e4abb1df2b00', '电影最TOP'), ('gh_438f512baa8c', '新浪娱乐'), ('gh_9d3dbb9ec4d7', '电影杂志'), ('gh_b09cb640f644', '吴晓波频道'), ('gh_1d320e454600', '谈心社'), ('gh_625a3729fa02', '有部电影'), ('gh_80dabfdf0a23', '肉叔电影'), ('gh_669fa2425fe6', '十点电影'), ('zhaoji-hk', '美美娱乐'), ('gh_f043697355c2', '电影派'), ('gh_4b9579801c0e', '电影头条'), ('gh_947200db0dec', '娱乐第一周刊'), ('gh_9190277c0ea0', '电影铺子'), ('gh_e3cf7cb85f44', '电影工厂'), ('gh_d2f3b9f6bd53', '韩国社'), ('gh_4369dbb814c3', '桃桃淘电影')]},{'341': [('gh_03756ca9d051', '熊宝辣妈'), ('gh_c4c06b514843', '六妈罗罗'), ('gh_300a7ccfa8eb', '丁香妈妈'), ('gh_cd33e3739712', '成长树'), ('gh_45260b7fafc7', '年糕妈妈'), ('gh_6a73a1af3762', '宝宝辅食微课堂'), ('gh_2f65ed73f82d', '丹妈读童书'), ('gh_e482d29a8d7a', '爱儿康'), ('gh_688f0b8f25d7', '爸妈营'), ('gh_938baa149c04', '小小包麻麻'), ('gh_c7663b32892a', '妈妈手册'), ('gh_e9455290cd6f', '崔玉涛的育学园'), ('gh_a279e468cec6', '鹏易讲故事'), ('gh_a758f750dd4f', '有养'), ('gh_a7003aeeedf7', '亲子营'), ('gh_888298519f5a', '凯叔讲故事'), ('gh_d6368cf4a0f8', '朵妈陪娃'), ('gh_dce846ef56b8', '窈窕妈妈'), ('gh_3f1800d1405a', '宝宝营养辅食'), ('gh_e2e08abce6d4', '拜托了妈妈')]},{'342': [('gh_5c7e8b7f586b', '十点读书'), ('gh_d9de5a6b1aa5', '有书'), ('gh_b988c7e2f64b', '洞见'), ('gh_476e9bd4e780', '百草园书店'), ('gh_ea08826e2531', '拾遗'), ('gh_7503151d035b', '每日豆瓣'), ('gh_0995175cf133', '学习小组'), ('gh_b97359a60d18', '国学文化'), ('gh_19942ed910de', '刘素云'), ('gh_d13fd2f38697', '每日一禅'), ('gh_177c72a269da', '国学生活'), ('gh_59cbf2ea5a57', '人教教材培训'), ('gh_9f53fee24d04', '福音满满耶稣爱你'), ('gh_a4af19d7a461', '慈怀读书会'), ('gh_48e6bb82a4b6', '祷告吧'), ('gh_acd98218b47a', '思想聚焦'), ('gh_259b512361a0', '易经'), ('gh_b89b5477caeb', '国家人文历史'), ('gh_b6af92efc51e', '林清玄读书会'), ('gh_59720cde0647', '读书有范')]},{'343': [('gh_944c12be2a75', '公关界的007'), ('gh_4cb202fe890f', '创业邦'), ('gh_4254cedf0117', '首席营销官'), ('gh_52611769f391', 'MBA智库'), ('gh_fd45cc72ae14', '品牌观察报'), ('gh_7418422c2a62', '廣告狂人'), ('gh_5323868cd99f', '哈佛商业评论'), ('gh_e8b5020147a7', '管理思维'), ('gh_1b12e286c254', '4A广告提案网'), ('gh_2dc11ff3574b', '商业学府'), ('gh_a1f75d561ef8', '首席品牌官'), ('wxid_6050960510211', '创业家'), ('gh_cc764ea0efaa', '刘润'), ('gh_740e26bcb5a8', '首席商业评论'), ('gh_8e2a8b22d7f6', '4A广告门'), ('gh_a28a687ad0e2', 'THLDL领导力'), ('gh_9c6c9ad32edd', 'MBA管理故事'), ('gh_a40ea005507f', 'SocialMarketing'), ('gh_ee2976b355d3', 'TOP创意广告'), ('gh_84fc6b07ab6d', '农视网')]},{'344': [('gh_1354d3dee7bb', '广东共青团'), ('gh_9cda6ee40e37', '共青团中央'), ('gh_dab5c199ae98', '中国政府网'), ('gh_0f71e49135c8', '中央纪委国家监委网站'), ('gh_27278ac0a645', '上海发布'), ('gh_9381891f8dd8', '共产党员'), ('gh_69039eaa6c69', '河南省教育厅'), ('gh_e0ec46ed865b', '江西共青团'), ('gh_5127e91ae3d7', '河北共青团'), ('gh_c6968641124b', '团中央学校部'), ('gh_a86e29353afa', '广州地铁'), ('gh_fb05d6c40471', '国家税务总局'), ('gh_575fcf857d89', '广东发布'), ('gh_f7279d1fbdc9', '杭州发布'), ('gh_90f03673657c', '重庆共青团'), ('gh_2bb6045fec3c', '陇南发布'), ('gh_6635e4d1209d', '中国普法'), ('gh_28428a1ba25a', '重庆交巡警'), ('gh_b869a72fd5c2', '青春山东'), ('gh_9a9eaca63e1a', '科普中国')]},{'345': [('gh_d2d870925c2e', '火星引力'), ('gh_984ed706049f', '有格'), ('gh_088decdf1338', '智谷趋势'), ('gh_520bcc60d396', '她街拍'),('gh_28974b5c0ad5', '一号哨位'), ('gh_5fbdb33c2018', '九句'), ('gh_1bf0f01eb04f', '艾辰八卦'), ('gh_e25d628d0a00', '乾坤使者园'), ('gh_b38f7a19e5d0', '劳动法库'), ('gh_12fed92d6e5a', '六点晨祷'), ('gh_7b3cb701d215', '陕西秦腔群'), ('gh_3010424e7e5f', '龙虎复兴'), ('gh_20437f2fbbd8', '民间实拍'), ('gh_5dfb4629dce7', '玩味成都'), ('gh_db90d8160c13', '萨克斯独奏'), ('gh_d4061c6a156a', '花果科技'), ('gh_d730cc9b2270', '龙部落'), ('gh_2d3b0329ba3b', '小提琴演奏')]}]

cate = {
    '327': '时事资讯',
    '328': '数码科技',
    '329': '汽车',
    '330': '房产家居',
    '331': '职场招聘',
    '332': '财经理财',
    '333': '生活',
    '334': '情感励志',
    '335': '女性时尚',
    '336': '旅游',
    '337': '运动健康',
    '338': '餐饮美食',
    '339': '搞笑娱乐',
    '340': '明星影视',
    '341': '母婴',
    '342': '文化教育',
    '343': '创业管理',
    '344': '政务',
    '345': '其他'
}
dic = {1: '时事资讯', 2: '数码科技', 3: '汽车', 4: '房产家居', 5: '职场招聘', 6: '财经理财', 7: '生活', 8: '情感励志', 9: '女性时尚', 10: '旅行', 11: '运动健康', 12: '餐饮美食', 13: '搞笑娱乐', 14: '明星影视', 15: '母婴', 16: '文化教育', 17: '创业管理', 18: '政务', 19: '企业', 20: '地方', 21: '其他'}

def get_fakeid():
    # 获取('gh_5dfb4629dce7', '玩味成都')
    cate_info = {
        '1':'327',
        '2':'328',
        '3':'329',
        '4':'330',
        '5':'331',
        '6':'332',
        '7':'333',
        '8':'334',
        '9':'335',
        '10':'336',
        '11':'337',
        '12':'338',
        '13':'339',
        '14':'340',
        '15':'341',
        '16':'342',
        '17':'343',
        '18':'344',
        '21':'345'}
    for k,v in cate_info.items():
        dic_cate = {}
        lis = []
        url = "https://data.wxb.com/rank?category={}&page=1".format(k)
        cate_v = v
        headers = {
            "x-requested-with": "XMLHttpRequest",
            "referer": "https://data.wxb.com/details/postRead?id=gh_363b924965e9",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36",
            "cookie": "Qs_lvt_288791=1547451887; Hm_lvt_5859c7e2fd49a1739a0b0f5a28532d91=1547451887; aliyungf_tc=AQAAAMkGmgkqsQIAz4oYJCoqIkYRfdEg; visit-wxb-id=2493b72ecf85c969396c1d20bd0c5ef0; wxb_fp_id=1637845248; PHPSESSID=a48960a353db6582acf46a5549b08a2e; Qs_pv_288791=3735833941120077300%2C2251690005355350000; RMU=1694159; RMT=8a4016940a902fd4fc5072773226eeaa; Hm_lpvt_5859c7e2fd49a1739a0b0f5a28532d91=1547619160"
        }
        a = requests.get(url, headers=headers)
        html = etree.HTML(a.content)
        list_source = html.xpath("//tbody[@class='ant-table-tbody']/tr/td[2]//div[@class='wxb-avatar-name']/a/text()")
        list_href = html.xpath("//tbody[@class='ant-table-tbody']/tr/td[2]//div[@class='wxb-avatar-name']/a/@href")
        list_href = [i.replace("/details/postRead?id=","") for i in list_href]
        aa = zip(list_href,list_source)
        for i in aa:
            lis.append(i)
        dic_cate.update({cate_v:lis})
        #print(dic_cate)
        time.sleep(20)


class GenerateCookie(object):
    def __init__(self):
        self.host = MYSQL_SETTINGS["MYSQL_HOST"]
        self.database = MYSQL_SETTINGS["MYSQL_DATABASE"]
        self.user = MYSQL_SETTINGS["MYSQL_USER"]
        self.password = MYSQL_SETTINGS["MYSQL_PASSWORD"]
        self.port = int(MYSQL_SETTINGS["MYSQL_PORT"])
        self.db = pymysql.connect(self.host, self.user, self.password, self.database, self.port, charset='utf8')
        self.cursor = self.db.cursor()
        self.table = COOKIE_TABLE

    def generate_cookie(self):
        # 模拟登陆获取cookie然后插入数据库
        url = 'https://account.wxb.com/login?from=https%3A%2F%2Fdata.wxb.com%2F'
        headers = {
            'Accept':'application/json, text/javascript, */*; q=0.01',
            'Accept-Encoding':'gzip, deflate, br',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Connection':'keep-alive',
            'Content-Length':'112',
            'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
            'Host':'account.wxb.com',
            'Origin':'https://account.wxb.com',
            'Referer':'https://account.wxb.com/?from=https%3A%2F%2Fdata.wxb.com%2F',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
            'X-Requested-With':'XMLHttpRequest'
        }
        gmt_update = time.strftime("%Y-%m-%d %X", time.localtime())
        for account,password in ACCOUNT.items():
            data = {
                'email':str(account),
                'password':password,
                'captcha':'',
                'remember':'on',
                'from':'https://data.wxb.com/'
            }
            res = requests.post(url,data,headers=headers)
            ret = res.headers.get("Set-Cookie")
            rmu = re.findall(r'RMU=(.*?);',ret,re.S)[0]
            if rmu == "deleted": #如果登陆失败发送通知邮件
                FailMail().send_mail("账号{}微小宝模拟登陆失败".format(account), res.content.decode())
                time.sleep(5)
            else: #登陆成功
                cookie = re.findall(r'PHPSESSID=(.*?);',ret,re.S)[0]
                platform = "微小宝"
                print(cookie)
                insert_sql = "insert into {}(platform,account,password,cookie,gmt_update) VALUES (%s, %s, %s,%s,%s) ON DUPLICATE KEY UPDATE platform=VALUES(platform),password=VALUES(password),cookie=VALUES(cookie),gmt_update=VALUES(gmt_update)".format(self.table)
                self.cursor.execute(insert_sql, (platform,account,password,cookie,gmt_update))
                self.db.commit()
                time.sleep(1)
        self.db.close()

    def get_cookie(self):
        # 从sql当中查询cookie
        sql = "select cookie from {}".format(self.table)
        self.cursor.execute(sql)
        info_list = self.cursor.fetchall()
        cookie_list = [cookie[0] for cookie in info_list]
        return cookie_list

if __name__ == '__main__':
    gc = GenerateCookie()
    gc.generate_cookie()
